<?php

namespace app\adminapi\exception;

use think\exception\Handle;
use think\exception\HttpResponseException;
use think\Response;
use Throwable;

/**
 * 应用异常处理类
 */
class HttpException extends Handle
{
    /**
     * Render an exception into an HTTP response.
     *
     * @access public
     * @param \think\Request $request
     * @param Throwable $e
     * @return Response
     */
    public function render($request, Throwable $e): Response
    {
        if ($e instanceof \think\exception\HttpException) {
//            var_dump($request->server('HTTP_SEC_FETCH_MODE'));exit();
            if($request->server('HTTP_SEC_FETCH_MODE') === 'navigate'){
                showMessage($e->getMessage(),"warning");
            }else{
                return json(error($e->getMessage(), $request, $e->getStatusCode()));
            }
        }
        return parent::render($request, $e);
    }
}
